import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    city: localStorage.getItem('n') || '北京',
    token: localStorage.getItem('token') || '',
    userId: localStorage.getItem('userId') || '',
    cityId: localStorage.getItem('cityId') || '110100'
  },
  mutations: {
    // 存储用户id
    setUserId(state, userId) {
      localStorage.setItem('userId', userId)
      state.userId = userId
    },
    // 存储token
    setToken(state, token) {
      localStorage.setItem('token', token)
      state.token = token
    },
    add(state, n) {
      localStorage.setItem('n', n)
      state.city = n
    },
    changeCityId(state, cityId) {
      localStorage.setItem('cityId', cityId)
      state.cityId = cityId
    }
  },
  actions: {},
  modules: {}
})
